/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Entity.Feedback;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author THANHDAT
 */
public class DAO_FeedBack {

    public DAO_FeedBack() {
    }

    public List<Feedback> showFeedBack() {
        try {
            List<Feedback> list = new ArrayList<Feedback>();
            String strSQL = "SELECT * FROM tblFeedBacks";
            Statement st = DAO_Connect.getConnection().createStatement();
            ResultSet rs = st.executeQuery(strSQL);
            while (rs.next()) {
                int id = rs.getInt(1);
                String title = rs.getString(2);
                String name = rs.getString(3);
                String date = rs.getString(4);
                String content = rs.getString(5);                
                Feedback feedback = new Feedback(title, name, date, content);
                list.add(feedback);
            }
            return list;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void insertFeedback(String title, String name, String date, String content) {
        String strSQL = "INSERT INTO tblFeedBacks VALUES (?,?,?,?)";
        boolean result = false;
        try {
            Connection conn = DAO_Connect.getConnection();
            PreparedStatement ps = conn.prepareCall(strSQL);
            ps.setString(1, title);
            ps.setString(2, name);
            ps.setString(3, date);
            ps.setString(4, content);
            ps.execute();
            ps.close();
        } catch (Exception e) {
            e.printStackTrace();
        }        
    }
}
